<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="test"></div>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <script src="./js/babel.min.js"></script>
    <script type="text/babel">
        class Test extends React.Component {
            constructor(props) {
                super(props)
                // 初始化必须写对象state
                this.state = {
                    isHot:true,
                    wind:'微风'
                }
                this.dome = this.dome.bind(this)
            }
            dome(){
                // state不可以直接更改，需要api来更改 需要setState来修改
                // this.state.isHot = !this.state.isHot;    错误写法
                const isHot = this.state.isHot
                this.setState({isHot:!isHot}) // 正确写法
            }
            render() { 
                const {isHot,wind} = this.state
                return <h1 onClick={this.dome}>今天天气很{this.state.isHot?'炎热':'凉爽'}，{wind}</h1>
            }
        }
        ReactDOM.render(<Test/>,document.getElementById("test"))
    </script>
</body>
</html>